import io.github.jonathanlink.PDFLayoutTextStripper;
import org.apache.pdfbox.io.RandomAccessFile;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.*;
import java.nio.ByteBuffer;

public class Main {
    public static void main(String[] args) throws IOException {
        String string = null;
        try {
            PDFParser pdfParser = new PDFParser(new RandomAccessFile(new File("D:\\ideaprojects\\PDF\\src\\main\\resources\\test.pdf"),"r"));
            pdfParser.parse();
            PDDocument pdDocument = new PDDocument(pdfParser.getDocument());
            int pages = pdDocument.getNumberOfPages();
            PDFTextStripper stripper = new CustomTextStripper();
//            stripper.setSortByPosition(true);
//            stripper.setStartPage(1);
//            stripper.setEndPage(pages);

            string = stripper.getText(pdDocument);
            String s1 = "D:\\ideaprojects\\PDF\\src\\main\\resources\\test0512.txt";

            FileOutputStream fileOutputStream = new FileOutputStream(s1);
            fileOutputStream.write(string.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        };

    }
}
